// Origin: https://www.programiz.com/c-programming/examples/source-code-output

#include <stdio.h>

int main()
{
    FILE *fp;
    int c;  // This is important to ensure a signed representation.
            // NEVER use char here for portability.
   
    // open the current input file
    fp = fopen(__FILE__, "r");
    // [XXX] Error checking is omitted here but that's usually NOT a good practice.

#if 0  // The original implementation is problematic and EOF is unexpectedly printed.
    do {
         c = getc(fp);   // read character 
         putchar(c);     // display character
    }
    while(c != EOF);  // loop until the end of file is reached
#endif
    for(;;) {
         c = getc(fp);        // read character 
         if(c == EOF) break;  // loop until the end of file is reached
         putchar(c);          // display character
    }
    
    fclose(fp);
    return 0;
}
